

using DataMongo;

﻿using DataMongo.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BreakingHubAdmin.Controllers
{
    public class PersonalDetailsController : Controller
    {
        //
        // GET: /PersonalDetails/
        public ActionResult PersonalDetail()
        {
            return View();
        }


        #region SexualOrientation

        public ActionResult SexualOrientation()
        {
            var connection = new RepositoryBaseMongo("SexualOrientation");
            var data = connection.GetAll<SexualOrientation>();
            return View(data);
        }

        public ActionResult AddSO()
        {
            var connection = new RepositoryBaseMongo("SexualOrientation");
            var SO = new SexualOrientation();
            return View(SO);
        }

        [HttpPost]
        public ActionResult AddSO(SexualOrientation sooo)
        {
            if (ModelState.IsValid)
            {
                var connection = new RepositoryBaseMongo("SexualOrientation");
                int Id = 0;
                var so = connection.GetAll<SexualOrientation>().ToList();
                if (so.Any())
                    Id = so.Max(x => x.SOId);
                Id += 1;
                sooo.SOId = Id;
                sooo.IsActive = true;
                connection.InsertOrUpdate(sooo);
                return RedirectToAction("SexualOrientation");
            }
            return null;
        }

        public ActionResult EditSO(int id)
        {

            var connection = new RepositoryBaseMongo("SexualOrientation");
            List<SexualOrientation> list = (from f in connection.GetAll<SexualOrientation>()
                                 where f.SOId == id
                                 select f).ToList();
            SexualOrientation so = new SexualOrientation();
            if (list.Count > 0) so = list[0];

            return View(so);
        }

        [HttpPost]
        public ActionResult EditSO(SexualOrientation so)
        {
            var connection = new RepositoryBaseMongo("SexualOrientation");
            List<SexualOrientation> list = (from f in connection.GetAll<SexualOrientation>()
                                 where f.SOId == so.SOId
                                 select f).ToList();
            SexualOrientation newso = new SexualOrientation();
            if (list.Count > 0) newso = list[0];
            so._id = newso._id;
            connection.InsertOrUpdate(so);
            return RedirectToAction("SexualOrientation");
        }

        public ActionResult DeleteSO(int id)
        {
            var connection = new RepositoryBaseMongo("SexualOrientation");
            List<SexualOrientation> list = (from f in connection.GetAll<SexualOrientation>()
                                 where f.SOId == id
                                 select f).ToList();
            SexualOrientation soo = new SexualOrientation();
            if (list.Count > 0) soo = list[0];
            connection.Delete<Source>(soo._id);
            return RedirectToAction("SexualOrientation");
        }


        #endregion

        #region TVHabit

        public ActionResult TVHabit()
        {
            var connection = new RepositoryBaseMongo("TVHabit");
            var data = connection.GetAll<TVHabit>();
            return View(data);
        }

        public ActionResult AddTVHabit()
        {
            var connection = new RepositoryBaseMongo("TVHabit");
            var TV = new TVHabit();
            return View(TV);
        }

        [HttpPost]
        public ActionResult AddTVHabit(TVHabit tv)
        {
            if (ModelState.IsValid)
            {
                var connection = new RepositoryBaseMongo("TVHabit");
                int Id = 0;
                var TVH = connection.GetAll<TVHabit>().ToList();
                if (TVH.Any())
                    Id = TVH.Max(x => x.TVHabitId);
                Id += 1;
                tv.TVHabitId = Id;
                tv.IsActive = true;
                connection.InsertOrUpdate(tv);
                return RedirectToAction("TVHabit");
            }
            return null;
        }

        public ActionResult EditTVHabit(int id)
        {

            var connection = new RepositoryBaseMongo("TVHabit");
            List<TVHabit> list = (from f in connection.GetAll<TVHabit>()
                                            where f.TVHabitId == id
                                            select f).ToList();
            TVHabit tv = new TVHabit();
            if (list.Count > 0) tv = list[0];

            return View(tv);
        }

        [HttpPost]
        public ActionResult EditTVHabit(TVHabit TV)
        {
            var connection = new RepositoryBaseMongo("TVHabit");
            List<TVHabit> list = (from f in connection.GetAll<TVHabit>()
                                            where f.TVHabitId == TV.TVHabitId
                                            select f).ToList();
            TVHabit tv = new TVHabit();
            if (list.Count > 0) tv = list[0];
            TV._id = tv._id;
            connection.InsertOrUpdate(TV);
            return RedirectToAction("TVHabit");
        }

       



        public ActionResult DeleteTVHabit(int id)
        {
            var connection = new RepositoryBaseMongo("TVHabit");
            List<TVHabit> list = (from f in connection.GetAll<TVHabit>()
                                            where f.TVHabitId == id
                                            select f).ToList();
            TVHabit tv = new TVHabit();
            if (list.Count > 0) tv = list[0];
            connection.Delete<Source>(tv._id);
            return RedirectToAction("TVHabit");
        }


        #endregion

        #region LivingStatus

        public ActionResult LivingStatus()
        {
            var connection = new RepositoryBaseMongo("LivingStatus");
            var data = connection.GetAll<LivingStatus>();
            return View(data);
        }

        public ActionResult AddLivingStatus()
        {
            var connection = new RepositoryBaseMongo("LivingStatus");
            var LS = new LivingStatus();
            return View(LS);
        }

        [HttpPost]
        public ActionResult AddLivingStatus(LivingStatus ls)
        {
            if (ModelState.IsValid)
            {
                var connection = new RepositoryBaseMongo("LivingStatus");
                int Id = 0;
                var LSS = connection.GetAll<LivingStatus>().ToList();
                if (LSS.Any())
                    Id = LSS.Max(x => x.LivingStatusId);
                Id += 1;
                ls.LivingStatusId = Id;
                ls.IsActive = true;
                connection.InsertOrUpdate(ls);
                return RedirectToAction("LivingStatus");
            }
            return null;
        }

        public ActionResult EditLivingStatus(int id)
        {

            var connection = new RepositoryBaseMongo("LivingStatus");
            List<LivingStatus> list = (from f in connection.GetAll<LivingStatus>()
                                  where f.LivingStatusId == id
                                  select f).ToList();
            LivingStatus ls = new LivingStatus();
            if (list.Count > 0) ls = list[0];

            return View(ls);
        }

        [HttpPost]
        public ActionResult EditLivingStatus(LivingStatus LS)
        {
            var connection = new RepositoryBaseMongo("LivingStatus");
            List<LivingStatus> list = (from f in connection.GetAll<LivingStatus>()
                                  where f.LivingStatusId == LS.LivingStatusId
                                  select f).ToList();
            LivingStatus ls = new LivingStatus();
            if (list.Count > 0) ls = list[0];
            LS._id = ls._id;
            connection.InsertOrUpdate(LS);
            return RedirectToAction("LivingStatus");
        }





        public ActionResult DeleteLivingStatus(int id)
        {
            var connection = new RepositoryBaseMongo("LivingStatus");
            List<LivingStatus> list = (from f in connection.GetAll<LivingStatus>()
                                  where f.LivingStatusId == id
                                  select f).ToList();
            LivingStatus ls = new LivingStatus();
            if (list.Count > 0) ls = list[0];
            connection.Delete<Source>(ls._id);
            return RedirectToAction("LivingStatus");
        }


        #endregion

        #region SocialSetting

        public ActionResult SocialSetting()
        {
            var connection = new RepositoryBaseMongo("SocialSetting");
            var data = connection.GetAll<SocialSetting>();
            return View(data);
        }

        public ActionResult AddSocialSetting()
        {
            var connection = new RepositoryBaseMongo("SocialSetting");
            var Socials = new SocialSetting();
            return View(Socials);
        }

        [HttpPost]
        public ActionResult AddSocialSetting(SocialSetting soci)
        {
            if (ModelState.IsValid)
            {
                var connection = new RepositoryBaseMongo("SocialSetting");
                int Id = 0;
                var socials = connection.GetAll<SocialSetting>().ToList();
                if (socials.Any())
                    Id = socials.Max(x => x.SocialSettingId);
                Id += 1;
                soci.SocialSettingId = Id;
                soci.IsActive = true;
                connection.InsertOrUpdate(soci);
                return RedirectToAction("SocialSetting");
            }
            return null;
        }

        public ActionResult EditSocialSetting(int id)
        {

            var connection = new RepositoryBaseMongo("SocialSetting");
            List<SocialSetting> list = (from f in connection.GetAll<SocialSetting>()
                                       where f.SocialSettingId == id
                                       select f).ToList();
            SocialSetting soc = new SocialSetting();
            if (list.Count > 0) soc = list[0];

            return View(soc);
        }

        [HttpPost]
        public ActionResult EditSocialSetting(SocialSetting SS)
        {
            var connection = new RepositoryBaseMongo("SocialSetting");
            List<SocialSetting> list = (from f in connection.GetAll<SocialSetting>()
                                       where f.SocialSettingId == SS.SocialSettingId
                                       select f).ToList();
            SocialSetting ss = new SocialSetting();
            if (list.Count > 0) ss = list[0];
            SS._id = ss._id;
            connection.InsertOrUpdate(SS);
            return RedirectToAction("SocialSetting");
        }





        public ActionResult DeleteSocialSetting(int id)
        {
            var connection = new RepositoryBaseMongo("SocialSetting");
            List<SocialSetting> list = (from f in connection.GetAll<SocialSetting>()
                                       where f.SocialSettingId == id
                                       select f).ToList();
            SocialSetting ss = new SocialSetting();
            if (list.Count > 0) ss = list[0];
            connection.Delete<Source>(ss._id);
            return RedirectToAction("SocialSetting");
        }


        #endregion

        #region Language

        public ActionResult Language()
        {
            var connection = new RepositoryBaseMongo("Language");
            var data = connection.GetAll<Language>();
            return View(data);
        }

        public ActionResult AddLanguage()
        {
            var connection = new RepositoryBaseMongo("Language");
            var language = new Language();
            return View(language);
        }

        [HttpPost]
        public ActionResult AddLanguage(Language lang)
        {
            if (ModelState.IsValid)
            {
                var connection = new RepositoryBaseMongo("Language");
                int Id = 0;
                var language = connection.GetAll<Language>().ToList();
                if (language.Any())
                    Id = language.Max(x => x.LanguageId);
                Id += 1;
                lang.LanguageId = Id;
                lang.IsActive = true;
                connection.InsertOrUpdate(lang);
                return RedirectToAction("Language");
            }
            return null;
        }

        public ActionResult EditLanguage(int id)
        {

            var connection = new RepositoryBaseMongo("Language");
            List<Language> list = (from f in connection.GetAll<Language>()
                                   where f.LanguageId == id
                                   select f).ToList();
            Language lang = new Language();
            if (list.Count > 0) lang = list[0];

            return View(lang);
        }

        [HttpPost]
        public ActionResult EditLanguage(Language langu)
        {
            var connection = new RepositoryBaseMongo("Language");
            List<Language> list = (from f in connection.GetAll<Language>()
                                   where f.LanguageId == langu.LanguageId
                                   select f).ToList();
            Language language = new Language();
            if (list.Count > 0) language = list[0];
            langu._id = language._id;
            connection.InsertOrUpdate(langu);
            return RedirectToAction("Language");
        }





        public ActionResult DeleteLanguage(int id)
        {
            var connection = new RepositoryBaseMongo("Language");
            List<Language> list = (from f in connection.GetAll<Language>()
                                   where f.LanguageId == id
                                   select f).ToList();
            Language lang = new Language();
            if (list.Count > 0) lang = list[0];
            connection.Delete<Language>(lang._id);
            return RedirectToAction("Language");
        }


        #endregion

    }
}